package xyz.kail.demo.websocket.spring.boot.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

public class HelloWebSocketHandler extends TextWebSocketHandler {

    private static Logger logger = LoggerFactory.getLogger(HelloWebSocketHandler.class);

    @Override
    protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {

        String payload = message.getPayload();
        logger.info(payload);

        TextMessage returnMessage = new TextMessage(" 收到消息 " + payload);
        session.sendMessage(returnMessage);
    }
}
